// 格式化时间函数，传入一个时间戳，得到一个年月日或年月日时分秒

const formatDate = (data, type) => {
    let time=null
    if(data){
        time = new Date(Number(data));
    }else{
        time = new Date();
    }
    if(!data&&!type){
        return new Date()
    }
    let year = time.getFullYear();
    let month = time.getMonth() + 1;
    let date = time.getDate();
    let hours=time.getHours();
    let minus=time.getMinutes();
    let second=time.getSeconds()
    month=month<10?'0'+month:month;
    date=date<10?'0'+date:date;
    hours=hours<10?'0'+hours:hours;
    minus=minus<10?'0'+minus:minus;
    second=second<10?'0'+second:second;
    switch (type) {
        case 1:
            return `${year}-${month}-${date}`  //返回YYYY-MM-DD
        case 2:
            return `${year}-${month}-${date} ${hours}:${minus}:${second}` //YYYY-MM-DD hh-mm-ss
        case 3:
            return `${year}-${month}-${date} 00:00:00` //YYYY-MM-DD 00:00:00
        case 4:
            return `${year}-${month}-${date} 23:59:59` //YYYY-MM-DD 23:59:59
        case 5:
            return `${hours}:${minus}` //23:59
        case 6:
            return `${year}-${month}-${date}`
        default:
            return `${year}-${month}-${date}`
            // break;
    }

}
export default formatDate